|
Radar Host Communication library
2020.08.13
|
This file defines the basic API to access Infineon sensor devices. More...
#include <stdint.h>Go to the source code of this file.
Data Structures | |
| struct | Firmware_Information_t |
| This structure contains information about the firmware. More... | |
| struct | Endpoint_Info_t |
| This structure contains information about an endpoint. More... | |
Macros | |
| #define | PROTOCOL_STATUS_OK 0x0000 |
| #define | PROTOCOL_STATUS_DEVICE_TIMEOUT 0x0001 |
| #define | PROTOCOL_STATUS_DEVICE_BAD_MESSAGE_START 0x0002 |
| #define | PROTOCOL_STATUS_DEVICE_BAD_ENDPOINT_ID 0x0003 |
| #define | PROTOCOL_STATUS_DEVICE_NO_PAYLOAD 0x0005 |
| #define | PROTOCOL_STATUS_DEVICE_OUT_OF_MEMORY 0x0006 |
| #define | PROTOCOL_STATUS_DEVICE_BAD_PAYLOAD_END 0x0007 |
| #define | PROTOCOL_STATUS_DEVICE_BAD_COMMAND 0xFFFF |
| #define | PROTOCOL_ERROR_INVALID_HANDLE -1 |
| #define | PROTOCOL_ERROR_COULD_NOT_OPEN_COM_PORT -100 |
| #define | PROTOCOL_ERROR_DEVICE_NOT_COMPATIBLE -101 |
| #define | PROTOCOL_ERROR_RECEIVED_NO_MESSAGE -1000 |
| #define | PROTOCOL_ERROR_RECEIVED_TIMEOUT -1001 |
| #define | PROTOCOL_ERROR_RECEIVED_BAD_MESSAGE_START -1002 |
| #define | PROTOCOL_ERROR_RECEIVED_BAD_MESSAGE_END -1003 |
| #define | PROTOCOL_ERROR_ENDPOINT_DOES_NOT_EXIST -2000 |
| #define | PROTOCOL_ERROR_ENDPOINT_WRONG_TYPE -2001 |
| #define | PROTOCOL_ERROR_ENDPOINT_VERSION_TOO_OLD -2002 |
| #define | PROTOCOL_ERROR_ENDPOINT_VERSION_TOO_NEW -2003 |
Functions | |
| int32_t | protocol_connect (const char *port_name) |
| This function establishes a connection to a device through a COM port. More... | |
| void | protocol_disconnect (int32_t protocol_handle) |
| This function closes an open connection. More... | |
| int32_t | protocol_get_num_endpoints (int32_t protocol_handle) |
| This function returns the number of endpoints in the connected device. More... | |
| int32_t | protocol_get_firmware_information (int32_t protocol_handle, Firmware_Information_t *information) |
| This function returns the information about the firmware of the connected device. More... | |
| int32_t | protocol_do_firmware_reset (int32_t protocol_handle) |
| This function triggers a firmware reset of the connected device. More... | |
| int32_t | protocol_get_endpoint_info (int32_t protocol_handle, uint8_t endpoint, Endpoint_Info_t *endpoint_info) |
| This function returns information about the requested endpoint. More... | |
| const char * | protocol_get_status_code_description (int32_t protocol_handle, int32_t status_code) |
| This function returns a human readable description of a status or error code. More... | |
| int32_t | protocol_poll_receive_once (int32_t protocol_handle) |
This file defines the basic API to access Infineon sensor devices.
The communication protocol is a generic protocol to exchange messages with microcontroller-based devices over a generic byte stream connection (typically a virtual serial port over USB). The communication is always initiated by the host, while the connected microcontroller device responds to messages received from the host.
The protocol defines two types of messages, payload messages and status messages. A payload message contains a block of data with arbitrary size and meaning. A status message contains a 16 bit status code. Messages from the host to the device are always payload messages. Whenever the device receives a payload message from the host, it responds with one (and only one) status message. The device may also send an arbitrary number of additional payload messages preceding that status message. Once the device has sent the status message, it won't send any more messages until it receives a new message from the host.
Each message from the host to the device is addressed to a certain logical endpoint and each message from the device to the host is sent from a logical endpoint. The number of logical endpoints is defined by the device. Endpoints are continuously enumerated starting with 1. At least one logical endpoint is always present. Endpoints are used to define functional groups in the device.
Each logical endpoint is of a defined type, which defines the meaning of the message payload exchanged with that endpoint. Additionally each endpoint has a version number that allows to distinguish between slight modifications of the endpoints set of known messages. The host can query type and version of the endpoints present in the device.
The API functions defined in this header file just allow basic access to the device, such as connecting, disconnecting and query endpoint information. The module Protocol.c further also implements functions for message exchange, but these functions are not meant to be used directly. Instead each type of endpoint should have a separate module that implements function to exchange messages tailored to the functionality of that endpoint. Those endpoint implementations may use the communication functions implemented in the module Protocol.c and declared in the header Protocol_internal.h.
Definition in file Protocol.h.
| int32_t protocol_connect | ( | const char * | port_name | ) |
This function establishes a connection to a device through a COM port.
This function tries to open the specified COM port. The COM port name must identify an existing COM port and is platform and machine specific. It is recommended to call com_get_port_list to get a list of available COM ports. Port names not in the returned list won't be accepted.
If the specified COM could be opened, information about the endpoints present in the connected device is queried. If endpoint information could not be retrieved properly, the device is considered to not be compatible with the communication protocol and the connection is closed again.
If a connection can be established, the function returns a handle that must be passed to all following function calls to identify the device. When the connection is not needed any more, it should be closed by calling protocol_disconnect.
| [in] | port_name | A zero-terminated string containing the device name of the COM port to use or the address of an UDP server in the form udp://server:port. |
Definition at line 573 of file Protocol.c.
| void protocol_disconnect | ( | int32_t | protocol_handle | ) |
This function closes an open connection.
If a valid handle to an open connection is provided, the according connection is closed and the handle is marked as invalid. If the handle is invalid, nothing will happen. Either way the handle must not be used any more after calling this function.
| [in] | protocol_handle | A handle to an open connection. |
Definition at line 723 of file Protocol.c.
| int32_t protocol_do_firmware_reset | ( | int32_t | protocol_handle | ) |
This function triggers a firmware reset of the connected device.
This function sends a message to the connected device to trigger a firmware ware reset and waits for the answer.
After calling this function, protocol_disconnect should be called immediately to ensure a proper reboot of the connected device.
| [in] | protocol_handle | A handle to an open connection returned. |
Definition at line 846 of file Protocol.c.
| int32_t protocol_get_endpoint_info | ( | int32_t | protocol_handle, |
| uint8_t | endpoint, | ||
| Endpoint_Info_t * | endpoint_info | ||
| ) |
This function returns information about the requested endpoint.
When the connection is established (see protocol_connect), information about the endpoints in the connected device is retrieved. This function returns information about the requested endpoints that was received when the connection was established. The endpoint information is not queried from the device again.
The caller must provide a valid pointer to a structure of type Endpoint_Info_t. That structure may be uninitialized.
| [in] | protocol_handle | A handle to an open connection. |
| [in] | endpoint | The number of the requested endpoint. (First endpoint is 1, not 0!) |
| [out] | endpoint_info | A pointer to the structure, where the endpoint information will be written to. |
Definition at line 890 of file Protocol.c.
| int32_t protocol_get_firmware_information | ( | int32_t | protocol_handle, |
| Firmware_Information_t * | information | ||
| ) |
This function returns the information about the firmware of the connected device.
This function sends a message to the connected device to query information about the firmware and waits for the answer. The reply message is evaluated and firmware information is written into the provided structure.
Note: This function allocates memory to hold the firmware description string. The caller must take core for freeing that memory when it's no longer needed.
| [in] | protocol_handle | A handle to an open connection returned. |
| [out] | information | A pointer to the structure, where the firmware information will be stored. |
Definition at line 768 of file Protocol.c.
| int32_t protocol_get_num_endpoints | ( | int32_t | protocol_handle | ) |
This function returns the number of endpoints in the connected device.
When the connection is established (see protocol_connect), information about the endpoints in the connected device is retrieved. A device compatible with the communication protocol contains at least one endpoint. If a board reports to have no endpoints, the connection won't be established. This function returns the number of endpoints received when the connection was established. The number of endpoints is not queried from the device again.
| [in] | protocol_handle | A handle to an open connection returned. |
Definition at line 755 of file Protocol.c.
| const char* protocol_get_status_code_description | ( | int32_t | protocol_handle, |
| int32_t | status_code | ||
| ) |
This function returns a human readable description of a status or error code.
Whenever a protocol or endpoint function returns a negative error code or a positive status code sent by an endpoint in a connected device, this function can be used to get a human readable description of that code.
The protocol handle is needed when retrieving a description for a status code sent by the device. When retrieving the description of a negative error code, the handle is ignored. This allows to retrieve error description in case a connection could not be established.
| [in] | protocol_handle | A handle to an open connection. |
| [in] | status_code | The status or error code to be described. |
Definition at line 1023 of file Protocol.c.
| int32_t protocol_poll_receive_once | ( | int32_t | protocol_handle | ) |
Definition at line 1151 of file Protocol.c.